home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / boot / netBoot / sun4.md / RCS / monalloc.c,v < prev    next >
Encoding:
Text File  |  1989-06-19  |  3.6 KB  |  183 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    mendel:1.1; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     89.06.19.14.22.31;  author mendel;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @@
  17.  
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @
  26. /*
  27.  * @@(#)monalloc.c 1.6 88/02/08
  28.  * Copyright (c) 1986 by Sun Microsystems, Inc.
  29.  */
  30.  
  31. /*
  32.  * monalloc.c
  33.  *
  34.  * ROM Monitor's routines for allocating resources needed on a temporary
  35.  * basis (eg, for initialization or for boot drivers).
  36.  *
  37.  * Note, all requests are rounded up to fill a page.  This is not a
  38.  * malloc() replacement!
  39.  */
  40.  
  41. #include "../sun3/cpu.map.h"
  42. #include "../sun3/cpu.addrs.h"
  43. #include "../dev/saio.h"
  44. #include "../h/globram.h"
  45.  
  46. /*
  47.  * Valid, supervisor-only, memory page's map entry.
  48.  * (To be copied to a map entry and then modified.)
  49.  */
  50. struct pgmapent mainmapinit = 
  51.     {1, PMP_SUP, VPM_MEMORY, 0, 0, 0};
  52.  
  53.  
  54. /*
  55.  * Say Something Here FIXME
  56.  */
  57. char *
  58. resalloc(type, bytes)
  59. register     enum RESOURCES type;
  60.      register unsigned bytes;
  61. {
  62.     register char *    addr;    /* Allocated address */
  63.     register char *    raddr;    /* Running addr in loop */
  64.  
  65.     if (bytes == 0)
  66.         return (char *)0;
  67.  
  68.     bytes = (bytes + (BYTESPERPG - 1)) & ~(BYTESPERPG - 1);
  69.  
  70.     switch (type) {
  71.  
  72.     case RES_RAWVIRT:
  73.         addr = gp->g_nextrawvirt;
  74.         gp->g_nextrawvirt += bytes;
  75.         return addr;
  76.  
  77.     case RES_DMAVIRT:
  78.         addr = gp->g_nextdmaaddr;
  79.         gp->g_nextdmaaddr += bytes;
  80.         return addr;
  81.  
  82.     case RES_MAINMEM:
  83.         addr = gp->g_nextrawvirt;
  84.         gp->g_nextrawvirt += bytes;
  85.         break;
  86.  
  87.     case RES_DMAMEM:
  88.         addr = gp->g_nextdmaaddr;
  89.         gp->g_nextdmaaddr += bytes;
  90.         break;
  91.  
  92.     default:
  93.         return (char *)0;
  94.     }
  95.     
  96.     /*
  97.      * Now map in main memory.
  98.      * Note that this loop goes backwards!!
  99.      */
  100.     for (raddr = addr;
  101.          bytes > 0;
  102.          raddr += BYTESPERPG, bytes -= BYTESPERPG,
  103.           gp->g_nextmainmap.pm_page -= 1) {
  104.         setpgmap(raddr, gp->g_nextmainmap);
  105.     } 
  106.  
  107.     return addr;
  108. }
  109.  
  110. struct pgmapent devmaps[] = {
  111. /* MAINMEM */
  112.     {1, PMP_SUP, VPM_MEMORY, 0, 0, 0},        
  113. /* OBIO */
  114.     {1, PMP_SUP, VPM_IO, 0, 0, 0},            
  115. /* MBMEM */
  116.     {1, PMP_SUP, VPM_VME16, 0, 0, 0xFF000000 >> BYTES_PG_SHIFT},        
  117. /* MBIO */
  118.     {1, PMP_SUP, VPM_VME16, 0, 0, 0xFFFF0000 >> BYTES_PG_SHIFT},        
  119. /* VME16A16D */
  120.     {1, PMP_SUP, VPM_VME16, 0, 0, 0xFFFF0000 >> BYTES_PG_SHIFT},        
  121. /* VME16A32D */
  122.     {1, PMP_SUP, VPM_VME32, 0, 0, 0xFFFF0000 >> BYTES_PG_SHIFT},        
  123. /* VME24A16D */
  124.     {1, PMP_SUP, VPM_VME16, 0, 0, 0xFF000000 >> BYTES_PG_SHIFT},        
  125. /* VME24A32D */
  126.     {1, PMP_SUP, VPM_VME32, 0, 0, 0xFF000000 >> BYTES_PG_SHIFT},        
  127. /* VME32A16D */
  128.     {1, PMP_SUP, VPM_VME16, 0, 0, 0x00000000 >> BYTES_PG_SHIFT},        
  129. /* VME32A32D */
  130.     {1, PMP_SUP, VPM_VME32, 0, 0, 0x00000000 >> BYTES_PG_SHIFT},        
  131. };
  132.  
  133.  
  134. /*
  135.  * devalloc() allocates virtual memory and maps it to a device
  136.  * at a specific physical address.
  137.  *
  138.  * It returns the virtual address of that physical device.
  139.  */
  140. char *
  141. devalloc(devtype, physaddr, bytes)
  142.     register enum MAPTYPES    devtype;
  143.     register char *        physaddr;
  144.     register unsigned    bytes;
  145. {
  146.     char *        addr;
  147.     register char *    raddr;
  148.     int        pages;
  149.     struct pgmapent    mapper;
  150.  
  151.     if (!bytes)
  152.         return (char *)0;
  153.  
  154.     pages = bytes + ((int)(physaddr) & (BYTESPERPG-1));
  155.     addr = resalloc(RES_RAWVIRT, pages);
  156.     if (!addr)
  157.         return (char *)0;
  158.  
  159.     mapper = devmaps[(int)devtype];        /* Set it up first */
  160.     mapper.pm_page += (int)(physaddr) >> BYTES_PG_SHIFT;
  161.  
  162.     for (raddr = addr;
  163.          pages > 0;
  164.          raddr += BYTESPERPG, pages -= BYTESPERPG,
  165.           mapper.pm_page -= 1) {
  166.         setpgmap(raddr, mapper);
  167.     } 
  168.  
  169.     return addr + ((int)(physaddr) & (BYTESPERPG-1));
  170. }
  171.  
  172. /*
  173.  * reset_alloc() does all the setup and all the releasing for the PROMs.
  174.  */
  175. reset_alloc()
  176. {
  177.     gp->g_nextrawvirt = BOOTMAP_BASE;
  178.     gp->g_nextdmaaddr = DVMA_BASE;
  179.     gp->g_nextmainmap = mainmapinit;
  180.     gp->g_nextmainmap.pm_page = (gp->g_memoryavail>>BYTES_PG_SHIFT) - 1;
  181. }
  182. @
  183.